package com.eastseeway.radioproject.base;

import android.app.Application;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;

import com.eastseeway.commonlib_esw.utils.SoundPoolUtil;
import com.eastseeway.radioproject.RadioApplication;
import com.eastseeway.radioproject.utils.SPHelper;

import java.util.concurrent.ExecutionException;

public abstract class BaseViewModel <T extends BaseRepository> extends AndroidViewModel {

    protected final T mRepository;
    private final Application mApplication;

    public BaseViewModel(@NonNull Application application) {
        super(application);
        mApplication = application;
        mRepository = setRepository();
    }

    protected abstract T setRepository();

    public boolean isNetConnected(){
        return mRepository.isNetConnected(mApplication);
//        try {
//        } catch (ExecutionException | InterruptedException e) {
//            throw new RuntimeException(e);
//        }
    }
    protected void playSound(){
        SoundPoolUtil.getInstance().play("click",0);
    }

    protected boolean isDeviceIdInvalid(){
        String deviceId = SPHelper.getDeviceId(getApplication());
        return deviceId.isEmpty();
    }
    protected void sendMessage(byte[] msg) {
        ((RadioApplication)mApplication).sendData(msg);
    }
}
